package com.dk.controller;

import com.dk.pojo.Area;
import com.dk.pojo.Location;
import com.dk.result.PageResult;
import com.dk.result.Result;
import com.dk.result.ResultConstant;
import com.dk.service.AreaService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("area")
@Api(tags = "库区接口文档")
public class AreaController {

    @Autowired
    private AreaService areaService;

    @GetMapping("getAreaInfo")
    @ApiOperation("库位模糊查询和分页查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "当前页"),
            @ApiImplicitParam(name = "pageSize", value = "每页显示条数"),
            @ApiImplicitParam(name = "code", value = "库位编码"),
            @ApiImplicitParam(name = "name", value = "库位名称"),
            @ApiImplicitParam(name = "positionX", value = "库位位置X"),
            @ApiImplicitParam(name = "positionY", value = "库位位置Y"),
            @ApiImplicitParam(name = "positionZ", value = "库位位置Z"),
            @ApiImplicitParam(name = "lid", value = "库区id",required = true)
    })
    public Result getAreaInfo(@RequestParam(defaultValue = "1")Integer pageNum,
                                  @RequestParam(defaultValue = "5") Integer pageSize,
                                  String code,String name,
                                  Integer positionX,  Integer positionY,Integer positionZ,
                                  Integer lid){
        PageResult<Area> result = areaService.getAreaInfo(pageNum,pageSize,code,name,positionX,positionY,positionZ,lid);
        return new Result(ResultConstant.CODE,ResultConstant.MESSAGE,result);
    }

    @PostMapping("addArea")
    @ApiOperation("库位增加")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "code", value = "库区编号",required = true),
            @ApiImplicitParam(name = "name", value = "库区名称",required = true),
            @ApiImplicitParam(name = "area", value = "库区面积",required = true),
            @ApiImplicitParam(name = "maxLoad", value = "最大载重量",required = true),
            @ApiImplicitParam(name = "standbyC", value = "是否启用:1是/2否",required = true),
            @ApiImplicitParam(name = "positionX", value = "库位位置X",required = true),
            @ApiImplicitParam(name = "positionY", value = "库位位置Y",required = true),
            @ApiImplicitParam(name = "positionZ", value = "库位位置Z",required = true),
            @ApiImplicitParam(name = "token", value = "登录后返回的token串",required = true),
            @ApiImplicitParam(name = "lid", value = "库区的id",required = true),
            @ApiImplicitParam(name = "remark", value = "备注")
    })
    public Result addArea(Area area,@RequestHeader String token){
        if(token == null || "".equals(token)){
            return new Result(ResultConstant.TOKEN_CODE, ResultConstant.TOKEN_MESSAGE);
        }
        return areaService.addArea(area,token);
    }

    @PutMapping("updateArea")
    @ApiOperation("库位修改")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "aid", value = "库区编号",required = true),
            @ApiImplicitParam(name = "code", value = "库区编号"),
            @ApiImplicitParam(name = "name", value = "库区名称"),
            @ApiImplicitParam(name = "area", value = "库区面积"),
            @ApiImplicitParam(name = "maxLoad", value = "最大载重量"),
            @ApiImplicitParam(name = "standbyC", value = "是否启用:1是/2否"),
            @ApiImplicitParam(name = "positionX", value = "库位位置X"),
            @ApiImplicitParam(name = "positionY", value = "库位位置Y"),
            @ApiImplicitParam(name = "positionZ", value = "库位位置Z"),
            @ApiImplicitParam(name = "token", value = "登录后返回的token串",required = true),
            @ApiImplicitParam(name = "lid", value = "库区的id"),
            @ApiImplicitParam(name = "remark", value = "备注")
    })
    public Result updateArea(Area area,@RequestHeader String token){
        if(token == null || "".equals(token)){
            return new Result(ResultConstant.TOKEN_CODE, ResultConstant.TOKEN_MESSAGE);
        }
        return areaService.updateArea(area,token);
    }

    @DeleteMapping("deleteArea")
    @ApiOperation("库位删除")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "aid", value = "库位id",required = true)
    })
    public Result deleteArea(Integer aid){
        areaService.deleteArea(aid);
        return new Result(ResultConstant.CODE,ResultConstant.MESSAGE);
    }
}